GBML manual / Collision

Autotile

A set of 13 (or 47) tiles that picks its own edge or corner from the squares around it. Draw the pieces once, then paint a pond, a wall or a path - in the Room Editor or while the game runs - and every shape gets the right edges and corners.

What an autotile is

Paint a pond with one tile and you get a square of water with no shore. To get a shore you paint the corners with corner tiles, the sides with edge tiles and the inside with a plain tile - and when you change the pond you have to fix them all by hand.

An autotile does that for you. It is a set of 13 pieces you draw once. When you paint with it, each square looks at the squares around it that belong to the same autotile and takes the piece that fits - and so do those neighbors. Paint an L-shaped bend, a U, a pond with an island in it: every edge and corner is right. Dig a hole in it and the squares around the hole get their inner corners.

The 13 pieces of an autotileThe 13 pieces of an autotile
The 13 pieces of an autotile

The pieces are a 3 x 3 block - four corners, four edges and the middle - and four inner corners. An inner corner is the middle of the shape with one corner missing: a square that has something on all four sides but is empty on one diagonal. You see them in a bend (where two arms meet) and around a hole.

Drawing a set (the Paint tab)

  1. Open a tile sheet - the kind of picture you paint rooms with, one square at a time - and open Autotiles in the left panel. A whole background picture, a sprite or a font cannot have autotiles.
  2. Press Create new autotile from scratch. A guide appears over a free part of the sheet: one labeled square for each piece you draw. The guide is only drawn over the picture, never into it. (Create from a template makes a whole autotile from a ready-made look, and Create from a top edge tile, just under it, draws a first try from one tile of yours: see below.)
  3. Draw each piece in its own square with the ordinary drawing tools. The section tells you how many pieces have something drawn.
  4. Press Ctrl+S. The autotile is saved with the picture.

Each piece is the square it sits in: the top edge is the square at that place of the sheet (a tile sheet is not reduced: square number N, counting left to right and then down, is tile N). Move the guide before you draw with the Move the guide button in the section (the guide follows your pointer; click the picture to put it down, press Esc or right-click to leave it where it was), because the pictures do not travel with it. Moving a guide is one step of undo (Ctrl+Z). A tileset can hold up to 16 autotiles. A piece cannot be on the top-left square of the sheet, square 0, which is the empty square.

Mirror corners and edges

With Mirror corners and edges ticked (it is ticked to begin with) you draw only five pieces and the console makes the other eight by flipping them - flipping a tile costs nothing:

You drawThe game makes
top-left cornertop-right corner (flipped sideways), bottom-left corner (flipped upside down), bottom-right corner (both)
top edgebottom edge (flipped upside down)
left edgeright edge (flipped sideways)
inner corner, top-leftthe other three inner corners (flipped sideways, upside down, both)
middle(nothing: it is its own)

A tile can be flipped but not turned, so the top edge and the left edge are both drawn. Untick the box to draw all 13 yourself - for light that comes from one side, say. Ticking or unticking it moves your drawings with their pieces (see When the guide does not fit below), so nothing you drew is lost.

The guide only takes squares for the pieces you draw, packed close: with Mirror ticked that is five squares in a row, and every slope angle you add puts its ramps side by side in the rows below. The pieces the console flips take no square and show no outline. With Mirror unticked the guide shows all 13 pieces, a block five squares wide and three tall. An autotile you drew on an older guide keeps its layout until you change its Mirror or its slopes: nothing moves by itself.

Mirror exceptions

Light that comes from one side may mean only some of the flipped pieces should really be flips. Under the Mirror box, a Mirror exceptions section (it shows only while Mirror is ticked, and starts closed) has three tickboxes. Each takes a group of pieces off the flip list, so they get squares and you draw them yourself:

The guide grows by the squares those pieces need. Unticking a group whose squares hold a drawing asks first, and keeps the drawing.

13 pieces or 47

The Pieces choice under the Mirror box says how many pieces the autotile has. 13 pieces is the set above. 47 pieces adds a piece for every other way the ground can meet the air, so a ring one square thick round a hole shows its outline on both of its open sides, a one-square-wide strip or a peninsula is outlined all the way round, and the stone-shaped corners of a brick wall turn up where bricks meet. It costs more tiles: 34 more pieces to draw, or 15 more with Mirror corners and edges (the new ones are flips of each other where they can be). The note under the choice says the number.

Choosing 47 changes nothing you can see at first: a piece you have not drawn yet is laid like a 13-piece one, in the Room Editor and in the game. Press Draw a first try to fill the empty pieces from the 13 you drew (each quarter of a new piece comes from the piece that has the same open sides), or use Create from a top edge tile to draw everything, and touch them up. The new squares go at the very end of the guide, so no piece you drew moves. Choosing 13 again takes the squares out of the guide; your drawings stay on the tileset. A look from Create from a template that would most benefit (stone, bricks, tiles, planks) comes as a 47-piece autotile.

When the guide does not fit

Ticking Include slopes, an angle or an exception, or unticking Mirror, needs more squares. If the picture has room, that is all. If not, the box stays as it was and a window, Make room for the guide, says how big the guide would be and what is missing, with a picture of the tileset and the guide (squares in the way in red, new rows tinted). It offers:

Each choice has a Preview tickbox, and the previews add up (mirror and taller together may need no new rows at all). Apply does exactly what the ticked previews show, as one undo step; a choice's own button applies that choice alone; Cancel changes nothing. A change that moves pieces saves the picture right away, so the rooms painted with the autotile follow at once and look the same.

Create from a template

Press Create from a template in the Autotiles section and a window opens with a handful of ready-made looks (meadow grass, cobblestone, dark rock, a cave, clouds, candy, glowing cracks and many more), in sections. Every section starts closed each time the window opens; the search box narrows the looks by name. Each look shows a small picture of itself in a room, with a hill, a hole and an overhang so you can judge the edges, and its cost: Uses 25 tiles is how many squares of your tileset it fills. Pick one and press Use this autotile.

Everything is made once, in the editor, when you press the button. Nothing is worked out while the game runs.

A first try from one tile

Press Create from a top edge tile (just under Create new autotile from scratch), then click ONE top edge tile on the tileset: the grass-topped dirt of a meadow, say. Gbabel reads it - the outline, a second band under the outline if there is one, the inside, and the speckles in the inside - shows a window, and draws a first try of every piece you draw into the guide. It is a first draft for you to touch up, made once in the editor; nothing is worked out while the game runs.

Shadow and depth

Two choices make the ground look solid instead of flat. Both are drawn ahead of time, in the editor.

How a square picks its layer: the shading follows a soft field, so the borders between layers wander like worn ground and never run along the tile grid. Gbabel measures how far each square is from the nearest square that is not part of the autotile (the air, a hole, a cliff; the ground carries on past the edge of the room), counting a step along a row or column as 5 and a diagonal step as 7. Next to the air it is an edge or a corner as always. Within two squares of the air it is the plain middle. Further in it is the deep layer, and further still the deepest (with Two layers, deep goes on); where one layer turns into the next is not a fixed distance but wanders a little from place to place, the same way every time you open the room. Nothing narrower than three squares is ever shaded deeper, so there are no lone dark squares, thin ridges or tongues, and the deepest layer never touches the plain one. Where a square has a neighbor, even one corner away, that is exactly one layer lighter, it takes a blend piece, laid flipped where the lighter ground is on the other side (the corner and the notch where the lighter ground comes from two sides, or only from a corner). So the shading rings round holes, cliffs and overhangs like lit ground, and there is no lit column under a hole. A piece you have not drawn yet is laid as the next simpler one (a blend as the layer's middle, then the plain middle), so a layer set up before its pieces are drawn never shows a hole. The Test pad shows the layers.

Rooms you painted earlier keep their shading until you change something beside it. Redo depth shading (in the Autotiles part of the Tile Palette, shown while the room has an autotile with layers) picks the layers again for the whole room with the current rule, as one step you can undo; squares whose piece you chose by hand keep it.

Face rows

For a top-down cliff or wall the front can be more than one square tall. The Face rows dropdown in the Autotiles section is 1, 2 or 3. With 1 nothing changes: the bottom edge is the whole front. With 2 or 3 you draw three more squares for each extra row (left, middle and right), and Gbabel lays them wherever a square has open ground exactly that many rows below it, with solid ground between. At the left and right ends of the front, and wherever the next column is a different height, it uses the left or right piece; inside it uses the middle one. The top row of a wall keeps its top edge, and a front that would reach the bottom of the room has no face, because the room's edge is never a wall.

Draw a first try and Create from a top edge tile fill the new squares with plain wall pieces; draw the real face over them. Face rows work with the brush, the bucket, Fill Room, erase, the hover preview and the slope tools in the Room Editor, with variant groups (every autotile of a group needs the same Face rows) and in your game with tile_set_auto and tile_clear_auto, which lay the same pieces the Room Editor does.

Groups of autotiles (variants)

A long stretch of one ground looks like wallpaper. Link two to four autotiles with the same layout into a variant group and a stretch of ground uses them all.

Moving autotiles (animated)

Water, swaying grass, glowing lava: some looks can move. Tick Include animated tiles for this set in the window of Create from a template (it appears only for looks that can move) or in Create from a top edge tile. There are two kinds, and the cost is shown before you press Apply.

The motion plays in the Room Editor's view while Play animated tiles is ticked (in the Tile Palette, under Tiles, Animated tiles), and in the game, with no code. The pictures of a sway are ordinary animated tiles (see tile animation): you can open them in the Paint tab under Animated tiles. Deleting an autotile deletes the animated tiles that move its pieces too, in the same undo step, and a line tells you how many went; the extra pictures stay on the tileset as ordinary art.

Painting with it (the Room Editor)

In the Room Editor, the Tile Palette has a Tiles part, and in it two parts of their own, Animated tiles and Autotiles (every part starts closed when Gbabel opens; click its name to open it).

Pick a brush and paint with Paint, Rect or Fill; the brush size works as it does for a tile.

A square belongs to an autotile when it holds one of its tiles. Nothing else is remembered, so a stroke painted last week is updated by a stroke painted today, and a room painted by hand with the same tiles is already painted with it. Two autotiles that share a tile would see each other's squares: give each its own tiles.

An autotile of another tileset

Every autotile in the game can be painted in any room, even one made from a different tileset. Pick its brush and paint: the squares are drawn from that tileset's picture, and the neighbors take their pieces as usual. Draw slope and Draw Curve work with it too. When you build, Gbabel puts the tiles the room takes from other tilesets together with the room's own into one ordinary sheet, ahead of time, so the console loads one sheet and pays nothing extra.

How a square picks its piece

Look at the four squares on the sides first:

  1. No square of the autotile on the left - the left column. Otherwise none on the right - the right column. Otherwise the middle column.
  2. No square above - the top row. Otherwise none below - the bottom row. Otherwise the middle row.
  3. A square in the middle of the middle (squares on all four sides) is the middle piece, unless a corner is empty: the first empty one, going top-left, top-right, bottom-right, bottom-left, gives that inner corner.

Every possible neighborhood gives one of the 13 pieces. (A set of 47 looks at the diagonal squares too: a diagonal only counts when the two squares beside it are filled, and every neighborhood then gives one of the 47. A square that touches a slope keeps the 13-piece rule.) Two things a set of 13 cannot show: a square with nothing around it is the top-left corner, and a line one square wide uses a left edge (a line that goes up and down) or a top edge (a line that goes across), with a corner at each end.

In your game

An autotile is also a word in code: AUTOTILE_ and its name in capital letters (a name with spaces uses _: "deep water" is AUTOTILE_DEEP_WATER). Two calls use it - tile_set_auto makes a square one of its squares and tile_clear_auto takes one away - and after each of them the square and the eight around it pick again, exactly as they do in the Room Editor.

tile_set_auto(x + 16, y, AUTOTILE_GRASS);

Makes the square 16 pixels ahead part of the grass: it takes the piece that fits, and its neighbors look again. A wall that grows, a pond that fills, a path that is trodden - the shape keeps its own edges and corners.

if (tile_index(x, y + 8) != 0) {
    tile_clear_auto(x, y + 8, AUTOTILE_GRASS);
}

Digs the square below: it becomes empty (if it was grass) and the squares around it take edges. Like tile_set_index, a change made while the game runs is not saved and does not survive a room change.

The autotile's collision, if it has any, goes on every square written and comes off the square that is cleared. So does a piece's slope: in the right-click window the Slopes part gives each of the 13 pieces a shape (the whole square, one of the slopes, or a shape you drew). A hill is the top-left corner as "floor rising to the right" and the top-right corner as "floor rising to the left"; the other pieces stay whole squares, so a hill painted with the autotile has ramps at its two ends. A piece only has a slope when the autotile blocks (Solid or Low cover). In the game, tile_set_auto writes the piece's slope along with its tile, and tile_clear_auto makes the square whole again. A game that never calls the two functions has none of this in it: it costs nothing and its game is exactly what it was. With several palettes on the sheet, a square takes the palette of its piece.

Slopes in an autotile

Tick Include slopes for an autotile in the Paint tab, then the angles you want (45, 22.5 and 11.25 degrees), and the guide gets more squares to draw. A 45 degree slope is one square, a 22.5 degree slope two squares side by side (the low one first), an 11.25 degree slope four. Each square is labeled ("floor ramp rising right: 1 of 2").

With Mirror corners and edges on you draw only the floor ramps that rise to the right. The ones that rise to the left are those flipped sideways, and a ceiling slope is its floor ramp flipped upside down: neither takes a square. For all three angles that is 12 squares in all, a block five squares wide and three tall. Untick Mirror, or tick Ceiling slopes under Mirror exceptions, to draw the ceilings yourself.

A glowing guide outline shows what each square needs: the ground line of an edge, the two sides of a corner, the notch of an inner corner and the stepped ramp of each slope square. It is only drawn over the picture, and Show guide outline hides it. Draw a first try fills the empty ramp squares from your top edge (floor ramps) and bottom edge (ceilings), and you repaint them; it never touches a square that already has a drawing.

In the Room Editor, pick the autotile and Draw slope appears under its brushes. It is the same button as in the Collision section, with Solid below (a floor) and Solid above (a ceiling). Press it, choose in the small popup which collision the slope gets (Pass, Solid or Low cover, and any of your own tile flags), and drag a line: it snaps to the nearest angle the autotile has and shows the ramp as you drag. Let go and the ramp is laid with the right slope in every square, and the ground beside it joins. A line that crosses squares of the autotile changes them too. One stroke is one undo. Every slope square the autotile includes must be drawn first.

Tick Steep slope pieces (under Include slopes, when 22.5 or 11.25 degrees is on) and the guide gets more squares: your 22.5 and 11.25 degree ramps turned a quarter turn are 67.5 and 78.75 degree pieces, one square wide and 2 or 4 squares tall, shown standing one above the other (with Mirror corners and edges that is 6 squares). A walker cannot walk up one: it is a wall with a slanted face that it slides down. Every piece takes one tile of the tileset. Create from a top edge tile and Draw a first try draw them for you by turning your ramps' pictures, and you touch them up. Draw Curve uses them where a curve climbs steeper than 45 degrees.

Tick Slope edge pieces (beside the angles) and the guide gets three more squares for each angle you keep: an under piece below each ramp square, and a crest and a foot where the ramp meets the flat ground. They are whole solid squares, flipped like the slope pieces, and they fill the band of grass or earth that would otherwise stop dead under a ramp. Draw slope and Draw Curve place them for you wherever the autotile already has those squares drawn; a square not drawn yet stays plain. Create from a top edge tile and Draw a first try make them too.

Closed shape, a tickbox beside Solid below / Solid above, is off to begin with. Unticked, the stroke changes only the squares the line crosses. Ticked, the solid side (under a floor slope, above a ceiling slope) is also filled with the autotile's usual pieces, as far as the first square of the autotile or the edge of the room.

Draw Curve, next to Draw slope, draws a curve in three clicks: where it starts, where it ends, then a third click for the bulge, which follows the pointer first. For every column Gbabel picks the nearest slope the autotile has (45, 22.5 or 11.25 degrees, rising either way) or a flat square, each joining the one before, and where the curve is steeper than 45 degrees it steps up in whole squares. It needs all three angles ticked, and Closed shape works for it too. Only the squares the curve crosses change.

A laid slope square is left as it is when you paint beside it, and in the game tile_set_auto and tile_clear_auto leave it alone too (it counts as part of the autotile for its neighbors).

Things to know

See also: tile_set_autotile_clear_autotile_set_indexTile flagsOne picture, several palettesTile animationCollision layers